//
//  HeroTalentViewController.m
//  LOL_JewelBox
//
//  Created by dllo on 15/4/22.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "HeroTalentViewController.h"
#import "HeroView.h"
#import "AFNetworking.h"
#import "UIImageView+WebCache.h"
@interface HeroTalentViewController ()<UIScrollViewDelegate>
@property(nonatomic, retain)NSMutableDictionary *heroDic;
@property(nonatomic, retain)UIScrollView *heroScrollView;
@property(nonatomic, retain)UIScrollView *subScrollView1;
@property(nonatomic, retain)UIScrollView *subScrollView2;
@end

@implementation HeroTalentViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.heroDic = [NSMutableDictionary dictionary];

    }
    return self;
    
    
}
- (void)dealloc
{
    [_heroDic release];
    [_heroName release];
    [_heroScrollView release];
    [_subScrollView2 release];
    [_subScrollView1 release];
    [super dealloc];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    [self heroData];


    // Do any additional setup after loading the view.


}
// 创建视图
- (void)createView
{
    HeroView *heroView = [[HeroView alloc] initWithFrame:CGRectMake(0, 0, VIEWWIDTH, VIEWHEIGHT)];
    [self.view addSubview:heroView];

    [heroView release];
    heroView.backgroundColor = [UIColor blackColor];

    self.heroScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, VIEWWIDTH, VIEWHEIGHT)];
    self.heroScrollView.pagingEnabled = YES;
    [heroView addSubview:self.heroScrollView];
    [_heroScrollView release];

    self.heroScrollView.contentSize = CGSizeMake(VIEWWIDTH * 2, VIEWHEIGHT);

    self.heroScrollView.minimumZoomScale = 0.5;
    self.heroScrollView.maximumZoomScale = 2;
    self.heroScrollView.delegate = self;
    for (NSInteger i = 0; i < 2; i++) {
        if (i == 0) {
             // 符文图片及介绍
            self.subScrollView1 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, VIEWWIDTH, VIEWHEIGHT)];
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,VIEWHEIGHT / 3 - 0.074962519 * VIEWHEIGHT, VIEWWIDTH, VIEWHEIGHT / 3)];
            NSURL *url = [NSURL URLWithString:self.heroDic[@"fuPic"]];
            [imageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"占位图"]];
            [self.subScrollView1 addSubview:imageView];
            imageView.userInteractionEnabled = YES;
            [imageView release];

            UILabel *fuDesc = [[UILabel alloc] initWithFrame:CGRectMake(0, VIEWHEIGHT / 3 * 2 - 0.074962519 * VIEWHEIGHT, VIEWWIDTH, VIEWHEIGHT / 3)];
            fuDesc.tag = 1005;
            fuDesc.text = self.heroDic[@"fuDes"];
            fuDesc.textColor = [UIColor whiteColor];
            fuDesc.numberOfLines = 0;
            fuDesc.lineBreakMode = NSLineBreakByWordWrapping;
            [self.subScrollView1 addSubview:fuDesc];
            [fuDesc release];
            [self.heroScrollView addSubview:self.subScrollView1];
            [_subScrollView1 release];
            self.subScrollView1.delegate = self;
            self.subScrollView1.minimumZoomScale = 0.5;
            self.subScrollView1.maximumZoomScale = 2;

        }
        if (i == 1) {
            //天赋图片及介绍
            self.subScrollView2 = [[UIScrollView alloc] initWithFrame:CGRectMake(VIEWWIDTH, 0, VIEWWIDTH, VIEWHEIGHT)];
            UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, VIEWHEIGHT / 3 - 0.074962519 * VIEWHEIGHT, VIEWWIDTH, VIEWHEIGHT / 3)];
            NSURL *url2 = [NSURL URLWithString:self.heroDic[@"tianPic"]];
            [imageView2 sd_setImageWithURL:url2 placeholderImage:[UIImage imageNamed:@"占位图"]];
            [self.subScrollView2 addSubview:imageView2];

            [imageView2 release];

            UILabel *talentDesc = [[UILabel alloc] initWithFrame:CGRectMake(0, VIEWHEIGHT / 3 * 2 - 50, VIEWWIDTH, VIEWHEIGHT / 3)];
            talentDesc.tag = 1006;
            talentDesc.text = self.heroDic[@"tianDes"];
            talentDesc.textColor  = [UIColor whiteColor];
            talentDesc.numberOfLines = 0;
            talentDesc.lineBreakMode = NSLineBreakByWordWrapping;
            [self.subScrollView2 addSubview:talentDesc];
            [talentDesc release];
            [self.heroScrollView addSubview:self.subScrollView2];
            [_subScrollView2 release];
            self.subScrollView2.delegate = self;
            self.subScrollView2.minimumZoomScale = 0.5;
            self.subScrollView2.maximumZoomScale = 2;

        }

    }













}
// 数据解析
- (void)heroData
{
    NSString *temp = [NSString stringWithFormat:@"http://box.dwstatic.com/apiHeroSuggestedGiftAndRun.php?v=70&hero=%@&OSType=iOS7.1.1",self.heroName];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:temp parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableArray *arr = responseObject;
        self.heroDic = [arr firstObject];
        [self createView];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    }];




}
#pragma mark  符文天赋图片放大 及切换自动还原
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
   return [scrollView.subviews firstObject];
}
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view
{   UILabel *temp1 = (UILabel *)[self.subScrollView1 viewWithTag:1005];
    UILabel *temp2 = (UILabel *)[self.subScrollView2 viewWithTag:1006];
    temp1.hidden = YES;
    temp2.hidden = YES;




}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSMutableArray *temp = [NSMutableArray arrayWithObjects:self.subScrollView1,self.subScrollView2,nil];
    for (UIScrollView *scorll in temp) {
        if (scorll.zoomScale != 1) {
            scorll.zoomScale = 1;
            UILabel *temp1 = (UILabel *)[self.subScrollView1 viewWithTag:1005];
            UILabel *temp2 = (UILabel *)[self.subScrollView2 viewWithTag:1006];
            temp1.hidden = NO;
            temp2.hidden = NO;
        }
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
